import React,{ useState } from 'react';
import {Text, View, Button, StyleSheet} from 'react-native';

export default function ( props ): React.JSX.Element {

  const data = props?.route?.params.data || '';
  const [params, setParams] = useState<any>(data);
  // 可以通过 route.params 获取传递的参数
  //setParams(props.route.params.data || '');

  function back(){
    props.route.params?.callback({ data: 'this is a callback data from Test1' });
    props.navigation.goBack();
  }

  return (
    <View style={styles.container}>
      <Text>Test1 Screen</Text>
      <View style={{marginTop: 20}}>
        <Text style={styles.text}>Received Params: {params}</Text>
      </View>
      <View style={{marginTop: 20}}>
        <Button title="Go back" onPress={() => back } />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {fontSize: 20, fontWeight: 'bold'},
});
